package com.jyz.until;

import com.jyz.mapper.RoleMapper;
import com.jyz.pojo.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class RoleMapperTest {
    SqlSession session;
    RoleMapper mapper;

    @Before
    public void before() {
        //1、创建SqlSessionFactory对象，也是单例模式的
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        //2、创建SqlSession对象 true 自动提交事务 不写也没事 因为默认在sqlsession关闭时提交事务
        session = factory.openSession(true);
        //3、调用session的方法namespace的名字.id
        mapper = session.getMapper(RoleMapper.class);

    }

    @After
    public void after() {
        //5、关闭资源
        session.close();
    }

    @Test
    public void selectRole_Permission() {
        List<Role> roles = mapper.selectRole_Permission();
        for (Role role : roles)
            System.out.println("role = " + role);
    }
    @Test
    public void selectRole_Permission_Lazy() {
        List<Role> roles = mapper.selectRole_Permission_lazy();
//        for (Role role : roles)
//            System.out.println("role = " + role);
    }

}